/*=============================================================================+
|                                                                              |
| Copyright 2012                                                               |
| Montage Inc. All right reserved.                                             |
|                                                                              |
+=============================================================================*/
/*-----------------------------------------------------------------------------+
| Common Macros                                                                |
+-----------------------------------------------------------------------------*/

#include <mt_types.h> //for using u8, etc..

//for Boot from flash
//move the config flash memory start address to the last block of flash
#define CFG_FLASH_ENCRYPT_START 0x10000
#define CFG_FLASH_MEM_LENGTH 0x1000

#define CFG_FLASH_RF_START   (CFG_FLASH_ENCRYPT_START + CFG_FLASH_MEM_LENGTH)
#define ALINK_FLASH_BOOT_START   (CFG_FLASH_RF_START + CFG_FLASH_MEM_LENGTH)
#define ALINK_DEVICE_INFO_START	(ALINK_FLASH_BOOT_START + CFG_FLASH_MEM_LENGTH)
//#define CFG_FLASH_MEM_START   (CFG_FLASH_RF_START + 0x1000)
//#define CFG_FLASH_MEM_START  (CFG_FLASH_RF_START + CFG_FLASH_MEM_LENGTH)
//#define CFG_FLASH_MEM2_START  (CFG_FLASH_MEM_START + CFG_FLASH_MEM_LENGTH)
//#define CFG_FLASH_BOOTINFO_START (CFG_FLASH_MEM2_START + CFG_FLASH_MEM_LENGTH)
//#define CFG_FLASH_WEBKEY_START (CFG_FLASH_BOOTINFO_START + CFG_FLASH_MEM_LENGTH)

#define MYLINKS_MAGIC			0x6658
#define CFG_MAGIC				{ 'M', 'C', 'F', 'G' }
#define CFG_CHKSUM_EN			(1<<31)
#define CFG_AUTO_CONN			(1<<30)
#define CFG_RECONN				(1<<29)
#define CFG_SAVE				(1<<28)
#define CFG_ALINK_DONE			(1<<27)
#define CFG_KONKE_DONE			(1<<26)
#define CFG_HT40				(1<<25)

typedef struct
{
	u8 enable;
	u8 duty;
}dc_moter_param;

typedef struct
{
	u8 enable;
	u8 angle;
}servo_moter_param;

typedef struct
{
	u8 enable;
	u8 r;
	u8 g;
	u8 b;
}rgbled_param;

typedef struct
{
	long baudrate;
	unsigned char  databits;
	unsigned char  stopbits;
	unsigned char  parity;
	unsigned char  flowctrl;
}uart_param;


typedef struct
{
	char ssid[32];
	char key[64];
	char channel;
	char enc;
	char max_con;
	char hidden_ssid;
	char ip[16];		/**< Static IP configuration, Local IP address. */
	char mask[16];		/**< Static IP configuration, Netmask. */
	char gw[16];		/**< Static IP configuration, Router IP address. */
}softap_param;


typedef struct
{
	char ssid[33];
	char key[65];
	char channel;
	char enc;
	unsigned char bssid[6];
}sta_param;


typedef struct
{
	unsigned char sta_mac[6];
	unsigned char ap_mac[6];
}mac_param;

typedef struct
{
	unsigned short check_sum;//用于判断配置文件是否正确
	u8 txpower;
	sta_param sta_param;
	mac_param mac;
	unsigned int boot;
	int cfg_magic;
}alink_rf_param;


typedef struct
{
	char startip[16];
	char endip[16];
	int leave_time;
}dhcps_param;

typedef struct
{
	u8 enable;			// 0:cancel trans mode when start;1:start
	char ip[16];
	int port;
	char type[4];
	int time_alive;
}trans_param;

typedef struct
{
	unsigned char cfg_magic[4];
	unsigned int flags;
	unsigned short chksum;
	u8 led_value;
	u8 work_mode;
	u8 dhcp_mode;
	u8 phy_mode;
	u8 txpower;
	u8 ps_mode;
	servo_moter_param sm_param;
	dc_moter_param dm_param;
	rgbled_param ledrgb_param;
	mac_param mac;
	uart_param ur_param;
	sta_param sta_param;
	softap_param ap_param;
	dhcps_param dhs_param;
	trans_param ts_param;
}sdk_param;


struct platform_sec_flag_param {
    u32 magic_num;
    u8 key[6];
};


/*-----------------------------------------------------------------------------+
| Function Prototypes                                                          |
+-----------------------------------------------------------------------------*/
int config_load(void);
int config_get(sdk_param *param);
int config_set(sdk_param *param);
int config_submit(void);
int config_erase(void);

